package com.objcat.servicea.config;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.annotation.NacosProperties;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.annotation.NacosConfigListener;
import com.alibaba.nacos.spring.context.annotation.config.EnableNacosConfig;
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * ClassName: TestConfig
 * Description:
 * <p>
 * date: 2020/7/24 13:06
 *
 * @author misheep
 * @since JDK 1.8
 */
//@Configuration
@Slf4j
//spring注解，配置应用上下文
@Configuration
//Nacos注解，启动Nacos Spring的配置管理服务
//@NacosProperties:全局和自定义Nacos属性的同一注解
@EnableNacosConfig(globalProperties = @NacosProperties(serverAddr = "127.0.0.1:8848"))
//加载数据源
@NacosPropertySource(dataId = "service-a-dev.yaml", autoRefreshed = true)
public class TestConfig {
    @NacosInjected
    private ConfigService configService;

    @PostConstruct
    public void init() {

    }

    @NacosConfigListener(dataId = "service-a-dev.yaml")
    public void onReceived(String value){
        log.info("onReceived: {}",value);
    }

}
